﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Drawing;
namespace TRIG_MOD_STATUSSUMMARY.DS_StatusSummaryCNT
{
    public partial class DS_StatusSummaryCNTUserControl : UserControl
    {
        public DS_StatusSummaryCNT ParentWebPart
        {
            get;
            set;
        }

        DataForStatusSummary objCls = new DataForStatusSummary();

        List<string> docTypes = new List<string>();
        List<string> discipAbb = new List<string>();

        public List<string> DocTypes
        {
            get { return docTypes; }
            set { docTypes = value; }
        }

        public List<string> Disciplines
        {
            get { return discipAbb; }
            set { discipAbb = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //docTypes = objCls.GetDocumentType(ddlDocsTypes);
                discipAbb = objCls.GetDiscipiline();
                DateValidation();
            }
            catch (Exception x)
            {

                errorMessage.Text += x.Message;
            }
            NullLabels();
        }

        private void DateValidation()
        {
            stDT.MaxDate = DateTime.Today;
            endDT.MaxDate = DateTime.Today;
            stSumGrid.DataSource = null;
            stSumGrid.Visible = false;
            if (Convert.ToInt32(rdDates.SelectedItem.Value) == 0)
            {
                endDT.Visible = false;
                stDT.IsRequiredField = true;
                stDT.SelectedDate = DateTime.Today;
            }
            else
            {
                endDT.Visible = true;
                stDT.IsRequiredField = true;
                endDT.IsRequiredField = true;
            }
        }

        protected void rdDates_SelectedIndexChanged2(object sender, EventArgs e)
        {
            stDT.ClearSelection();
            endDT.ClearSelection();
            stSumGrid.DataSource = null;
            stSumGrid.Visible = false;
            lblr1.Text = ""; lblr2.Text = ""; lblr3.Text = ""; lblr4.Text = ""; lblr5.Text = ""; lbl_R1.Text = ""; lbl_R2.Text = ""; lbl_R3.Text = ""; lbl_R4.Text = ""; lbl_R5.Text = "";
            errorMessage.Text = "";
        }

        protected void btnProcess_Click(object sender, EventArgs e)
        {

        }

        //protected void btnProcess_Click1(object sender, EventArgs e)
        //{

        //    //docTypes = objCls.GetDocumentType(ddlDocsTypes);
        //    NullLabels();
        //    discipAbb = objCls.GetDiscipiline();
        //    objCls.CreateTable("DS");
        //    objCls.Group = ("CNT");
        //    objCls.rdDates = rdDates;
        //    if (Convert.ToInt32(rdDates.SelectedItem.Value) == 1) // As of Today
        //        GetDates();
        //    else
        //        GetDates("Today");
        //    objCls.grid = stSumGrid;

        //    //if (objCls.ckItemsInDocs(ParentWebPart.docTypeName) > 0)
        //    //{
        //    //    objCls.GetDocItemsbyDiscipiline(ParentWebPart.docTypeName, Disciplines, errorMessage, "DS");
        //    //}

        //    int ck = objCls.GetDocItemsbyDiscipiline_DS(ParentWebPart.docTypeName, Disciplines, errorMessage, "DS");
        //    if (ck > 0)
        //    {
        //        objCls.BindGrid(stSumGrid, lbl_R1, lbl_R2, lbl_R3, lbl_R4, lbl_R5, "DS");
        //        string p = " % of MSs ";
        //        lblr1.Text = "Under Review" + p;
        //        lblr2.Text = "Approved (Code : 1) as per total submitted" + p;
        //        lblr3.Text = "Approved as noted (Code : 2) as per total submitted" + p;
        //        lblr4.Text = "Not Approved (Code : 3) as per total submitted" + p;
        //        lblr5.Text = "Superseded as per total submitted" + p;
        //    }
        //    else { }
            
            
        //    //if (objCls.ckCnt > 0)
        //    //{
        //    //    objCls.BindGrid(stSumGrid, lbl_R1, lbl_R2, lbl_R3, lbl_R4,lbl_R4, "DS");
        //    //    string p = "% of DS ";

        //    //    lblr1.Text = "Under Review" + p;
        //    //    lblr2.Text = "Approved (Code : 1) as per total submitted" + p ;
        //    //    lblr3.Text = "Approved as noted (Code : 2) as per total submitted" + p ;
        //    //    lblr4.Text = "Not Approved (Code : 3) as per total submitted" + p ;
        //    //    lblr5.Text = "Superseded as per total submitted" + p;
        //    //}
        //    //else { errorMessage.Text = "No Records Found"; errorMessage.ForeColor = System.Drawing.Color.Green; stSumGrid.Visible = false; }
        //}


        private void NullLabels()
        {
            lblr1.Text = ""; lblr2.Text = ""; lblr3.Text = ""; lblr4.Text = ""; lblr5.Text = ""; lbl_R1.Text = ""; lbl_R2.Text = ""; lbl_R3.Text = ""; lbl_R4.Text = ""; lbl_R5.Text = "";
            errorMessage.Text = "";
            stSumGrid.Visible = true;
        }

        private void GetDates(string today)
        {
            string startDt = Convert.ToString(stDT.SelectedDate.ToShortDateString());
            objCls.cpStDT = startDt;
            objCls.cpEndDT = startDt;

        }

        private void GetDates()
        {
            //stDT.IsRequiredField = true;
            //endDT.IsRequiredField = true;
            string startDt = Convert.ToString(stDT.SelectedDate.ToShortDateString());
            string endDt = Convert.ToString(endDT.SelectedDate.ToShortDateString());
            objCls.cpStDT = startDt;
            objCls.cpEndDT = endDt;

        }

        protected void btnProcessDS_Click(object sender, EventArgs e)
        {
            //docTypes = objCls.GetDocumentType(ddlDocsTypes);
            NullLabels();
            discipAbb = objCls.GetDiscipiline();
            objCls.CreateTable("DS");
            objCls.Group = ("CNT");
            objCls.rdDates = rdDates;
            if (Convert.ToInt32(rdDates.SelectedItem.Value) == 1) // As of Today
                GetDates();
            else
                GetDates("Today");
            objCls.grid = stSumGrid;

            //if (objCls.ckItemsInDocs(ParentWebPart.docTypeName) > 0)
            //{
            //    objCls.GetDocItemsbyDiscipiline(ParentWebPart.docTypeName, Disciplines, errorMessage, "DS");
            //}

            int ck = objCls.GetDocItemsbyDiscipiline_DS(ParentWebPart.docTypeName, Disciplines, errorMessage, "DS");
            if (ck > 0)
            {
                objCls.BindGrid(stSumGrid, lbl_R1, lbl_R2, lbl_R3, lbl_R4, lbl_R5, "DS");
                string p = " % of MSs ";
                lblr1.Text = "Under Review" + p;
                lblr2.Text = "Approved (Code : 1) as per total submitted" + p;
                lblr3.Text = "Approved as noted (Code : 2) as per total submitted" + p;
                lblr4.Text = "Not Approved (Code : 3) as per total submitted" + p;
                lblr5.Text = "Superseded as per total submitted" + p;
            }
            else { }


            //if (objCls.ckCnt > 0)
            //{
            //    objCls.BindGrid(stSumGrid, lbl_R1, lbl_R2, lbl_R3, lbl_R4,lbl_R4, "DS");
            //    string p = "% of DS ";

            //    lblr1.Text = "Under Review" + p;
            //    lblr2.Text = "Approved (Code : 1) as per total submitted" + p ;
            //    lblr3.Text = "Approved as noted (Code : 2) as per total submitted" + p ;
            //    lblr4.Text = "Not Approved (Code : 3) as per total submitted" + p ;
            //    lblr5.Text = "Superseded as per total submitted" + p;
            //}
            //else { errorMessage.Text = "No Records Found"; errorMessage.ForeColor = System.Drawing.Color.Green; stSumGrid.Visible = false; }
        }
    }
}
